<?php if (!defined('THINK_PATH')) exit();?><section class="content-header" >
	<h1>
		角色管理
		<small>角色列表</small>
	</h1>
	<ol class="breadcrumb">
		<li><a href="<?php echo U('Admin/index');?>"><i class="fa fa-home"></i>首页</a></li>
		<li class="active">角色列表</li>
	</ol>
</section>
<!-- Main content -->
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
				<div class="box-header">
					<div class="box-title"><label >角色列表</label></div>
					<div class="pull-right">
						<button class="btn btn-block btn-primary btn-sm" onclick="adminRoleListAdd(0)"><i class="fa fa-plus"></i>&nbsp;&nbsp;&nbsp;添加角色</button>
					</div>
				</div><!-- /.box-header -->
				<div class="box-body">
					<table id="table" class="table table-bordered table-striped" width="100%">
						<thead>
						<tr>
							<th style="width: 40px">排序</th>
							<th>ID</th>
							<th>角色名称</th>
							<th>角色描述</th>
							<th>状态</th>
							<th>操作</th>
						</tr>
						</thead>
					</table>
				</div><!-- /.box-body -->
			</div><!-- /.box -->
		</div><!-- /.col -->
	</div><!-- /.row -->
</section><!-- /.content -->
<!-- DATA TABES SCRIPT -->
<!-- page script -->
<script type="text/javascript">
	$(function () {
		$('#table').dataTable({
			"processing": true, //载入数据的时候是否显示“载入中”
//             ordering: false, //排序操作在服务端进行，所以可以关了。
			"order": [0,'desc'],
			"searching": false,
			'serverSide': true,
			"ajax": "<?php echo U('Admin/rolePager');?>",
			"columns": [
				{"data": "roleid"},
				{"data": "roleid","orderable":false},
				{"data": "rolename","orderable":false},
				{"data": "description","orderable":false},
				{"data": "disabled","orderable":false},
				{"data": "roleid","orderable":false}
			],
			"columnDefs": [
				{
					"targets": 0,
					"render": function (data, type, row) {
						return '<input type="text" id="role'+data+'" value="'+row.listorder+'" style="text-align:center;height: 20px" size="2" onchange="adminRoleListOrder('+data+')"/>';
					}
				},
				{
					"targets": 4,
					"render": function (data, type, row) {
						return data==0?'已启用':'已禁用';
					}
				},
				{
					"targets": 5,
					"render": function (data, type, row) {
						if(data==1){
							return "";
						}
						return '<a href="javascript:adminRoleListAdd(' +data + ')"><i class="fa fa-edit"></i>&nbsp;编辑</a>' +
								'&nbsp;&nbsp;&nbsp;<a href="javascript:adminRoleListDelete(' +data + ')"><i class="fa fa-trash-o"></i>&nbsp;删除</a>' +
								'&nbsp;&nbsp;&nbsp;<a href="javascript:adminRoleListPermission(' +data + ')"><i class="fa fa-angle-double-right"></i>&nbsp;权限设置</a>';
					}
				}
			],
			"language": lang
		});
	});

	//排序
	function adminRoleListOrder(id){
		$.post('<?php echo U("Admin/roleOrder");?>', "order="+$('#role'+id).val()+"&id="+id, function(res){
			if(!res.status){
				$.messager.alert('提示信息', res.info, 'error');
			}else{
				reloadContent();
			}
		}, 'json');
	}

	//添加
	function adminRoleListAdd(id){
		var data = null;
		var title = "添加角色";
		if(id){
			data = "id="+id;
			title = '编辑角色';
		}
		$.dialog("<?php echo U('Admin/roleAdd');?>", title, data,42);
	}

	//删除
	function adminRoleListDelete(id){
		$.messager.confirm('提示信息', '确定要删除吗？', function(result){
			if(!result) return false;
			$.post("<?php echo U('admin/roleDelete');?>", {id: id}, function(res){
				if(!res.status){
					$.messager.alert('提示信息', res.info, 'error');
				}else{
					$.messager.alert('提示信息', res.info, 'info');
					reloadContent();
				}
			}, 'json');
		});
	}

	//角色权限
	function adminRoleListPermission(id){
		var url = "<?php echo U('Admin/rolePermission');?>";
		url += url.indexOf('?') != -1 ? '&id='+id : '?id='+id;
		$.dialog(url, '角色权限', null);

	}

</script>